{layout name="layout" /}

<div class="product-management">
    <h2>商品信息管理</h2>
    
    <form class="search-form" method="get" action="">
        <div class="form-group">
            <input type="text" name="keyword" placeholder="输入商品名称或ID" value="{$keyword}">
            <button type="submit">查询</button>
            <a href="{:Url('admin/product/productNew')}" class="btn-add">新增商品</a>
        </div>
    </form>
    
    <div class="product-table-container">
        <table class="product-table">
            <thead>
                <tr>
                    <th width="80">商品名称</th>
                    <th width="120">商品图片</th>
                    <th width="100">价格(¥)</th>
                    <th>简介</th>
                    <th width="100">商品类别</th>
                    <th width="180">操作</th>
                </tr>
            </thead>
            <tbody>
                {foreach name="products" item="data"}
                <tr>
                    <td class="product-name">{$data.pName|substr=0,20}</td>
                    <td>
                        {if condition="$data.pImg"}
                        <img src="__STATIC__/upload/{$data.pImg}" class="product-thumb">
                        {else}
                        <span class="no-image">无图片</span>
                        {/if}
                    </td>
                    <td class="text-right">{$data.pPrice}</td>
                    <td>
                        {if condition="mb_strlen($data.pDescr, 'utf-8') > 30"}
                            {$data.pDescr|mb_substr=0,30,'utf-8'}...
                        {else /}
                            {$data.pDescr}
                        {/if}
                    </td>
                    <td>
                        {php}
                            $category = \think\Db::name('class')
                                ->where('cId', $data['pClassId'])
                                ->value('cName');
                            echo $category ?: '未分类';
                        {/php}
                    </td>
                    <td class="actions">
                        <a href="{:Url('admin/product/update', ['id' => $data.pId])}" class="btn-edit">编辑</a>
                        <a href="{:Url('admin/product/delete', ['id' => $data.pId])}" 
                           onclick="return confirm('确定要删除该商品吗？')" 
                           class="btn-delete">删除</a>
                        <a href="{:Url('admin/product/detail', ['id' => $data.pId])}" class="btn-detail">详情</a>
                    </td>
                </tr>
                {/foreach}
            </tbody>
        </table>
    </div>
    
    <div class="pagination-wrapper">
        {$products->render()}
    </div>
</div>